/*
 * @lc app=leetcode.cn id=69 lang=typescript
 *
 * [69] x 的平方根
 */

// @lc code=start
function mySqrt(x: number): number {
    let final = x;
    while (final > 0) {
        final = Math.ceil(final / 2);
        if (final * final <= x) {
            break;
        }
    }
    while (final * final <= x) {
        final++;
    }
    return final - 1;
}
// @lc code=end
